class Solution {
    public int minimumCardPickup(int[] cards) {
        Map<Integer, Integer> mp = new HashMap<>();
        int ans = 100010;
        boolean flag = false;
        for (int i = 0; i < cards.length; i++) {
            if (mp.containsKey(cards[i])) {
                flag = true;
                ans = Math.min(ans, i + 1 - mp.get(cards[i]) + 1);
            }
            mp.put(cards[i], i + 1);
        }return flag ? ans : -1;
    }
}